#ifndef _SHARED_H_20160331
#define _SHARED_H_20160331

#if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER>1600)
#include <functional>
using std::function;
#else
#include <tr1/functional>
using std::tr1::function;
#endif

char* CloneTextData(char* ps);
char* CloneTextData(char* ps, INT nTextLen);
void GReportError(char* szErrText);
void* MMalloc(INT nSize);
void MFree(void* p);
void* MMallocArray(int nCount);
void MFreeArray(INT dtType, void** ppAryData);
LPBYTE GetAryElementInf(void* pAryData, LPINT pnElementCount);

template<typename T>
void MFreePArray(void** ppAryData, const function<void(T*)>& fn)
{
	if (NULL == *ppAryData) return;
	INT count;
	LPINT pAry = (LPINT)GetAryElementInf(*ppAryData, &count);
	for (INT i = 0; i < count; ++i){
		T** ppObj = (T**)pAry[i];
		fn(*ppObj);
		MFree(ppObj);
	}
	MFree(*ppAryData);
}

#define DTT_IS_NULL_DATA_TYPE   0
#define DTT_IS_SYS_DATA_TYPE    1
#define DTT_IS_USER_DATA_TYPE   2
#define DTT_IS_LIB_DATA_TYPE    3
INT GetDataTypeType(DATA_TYPE dtDataType);

#endif